home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / textual / tex / files / !tex / TeXsource / commontex / c / str < prev   
Encoding:
Text File  |  1988-04-08  |  1.4 KB  |  98 lines

  1. /*
  2.  *    Copyright 1986, 1987 Pat Joseph Monardo. All rights reserved.
  3.  *    Copying of this file is granted according to the provisions 
  4.  *    specified in the file COPYING which must accompany this file.
  5.  */
  6.  
  7.  
  8. /*
  9.  *        str.c
  10.  */
  11.  
  12. #include "tex.h"
  13. #include "io.h"
  14. #include "file.h"
  15. #include "error.h"
  16. #include "str.h"
  17.  
  18. ascii     str_pool[POOL_SIZE];
  19. ptr        pool_ptr;
  20. ptr        str_start[MAX_STRINGS];
  21. str        str_ptr;
  22. str        null_str;
  23.  
  24. bool
  25. str_eq_buf (s, k)
  26.     str        s;
  27.     int        k;
  28. {
  29.     int        j;
  30.     
  31.     j = str_start[s];
  32.     while (j < str_start[s + 1]) {
  33.         if (str_pool[j] != buffer[k])
  34.             return FALSE;
  35.         incr(j); incr(k);
  36.     }
  37.     return TRUE;
  38. }
  39.  
  40. bool
  41. str_eq_str (s, t)
  42.     str        s;
  43.     str        t;
  44. {
  45.     int        j;
  46.     int        k;
  47.  
  48.     if (length(s) != length(t))
  49.         return FALSE;
  50.     j = str_start[s];
  51.     k = str_start[t];
  52.     while (j < str_start[s + 1]) {
  53.         if (str_pool[j] != str_pool[k])
  54.             return FALSE;
  55.         incr(j); incr(k);
  56.     }
  57.     return TRUE;
  58. }
  59.  
  60. str
  61. make_string ()
  62. {
  63.     incr(str_ptr);
  64.     if (str_ptr == MAX_STRINGS)
  65.         overflow("number of strings", MAX_STRINGS);
  66.     str_start[str_ptr] = pool_ptr;
  67.     return (str_ptr - 1);
  68. }
  69.  
  70. str
  71. make_string_given (s)
  72.     char*     s;
  73. {
  74.     while (*s != NUL) {
  75.         append_char(*s);
  76.         incr(s);
  77.     }
  78.     return (make_string());
  79. }
  80.  
  81. init_strings ()
  82. {
  83.     int     k;
  84.  
  85.     str_ptr = pool_ptr = 0;
  86.     for (k = 0; k <= 127; incr(k)) {
  87.         if (k < ' ') {
  88.             append_char('^');
  89.             append_char('^');
  90.             append_char(k + 0100);
  91.         } else if (k == 127)
  92.             make_string_given("^^?");
  93.         else append_char(k);
  94.         make_string();
  95.     }
  96.     null_str = make_string();
  97. }
  98.